package com.wkbb.basic.thread;

import com.wkbb.basic.feign.DoorFeignService;
import com.wkbb.basic.model.Student;
import com.wkbb.basic.model.User;
import com.wkbb.basic.service.StudentService;
import com.wkbb.basic.service.UserService;
import com.wkbb.common.enums.ChangeClassOperateTypeEnum;
import com.wkbb.common.utils.ThreadPoolUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;

import java.util.HashMap;
import java.util.List;

/**
 * 异步更新用户redis
 * */
@Slf4j
public class UpdateOrgUserRedisTask implements Runnable {

    private UserService userService;
    private Long orgId;

    public UpdateOrgUserRedisTask(UserService userService, Long orgId) {
        this.userService = userService;
        this.orgId = orgId;
    }

    @Override
    public void run() {
        try {
            log.info("异步更新用户redis开始.....orgId:{}", orgId);

            //变更学校名称删除当前学校所有用户缓存
            HashMap<String, Object> param = new HashMap<>();
            param.put("orgId",orgId);
            List<User> userList = userService.getListByMapParams(param);
            if(CollectionUtils.isNotEmpty(userList)){
                userList.forEach((e)->{
                    userService.updateUserInfo(orgId,e.getId());
                });
            }

            log.info("异步更新用户redis结束.....orgId:{}", orgId);
        } catch (Exception e) {
            log.error("异步更新用户redis异常，{}", e.getMessage());
        }
    }

}
